<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">
	<ui:composition template="/templates/padrao.xhtml">
		<ui:define name="barraTitulo">Cadastro de Grupo</ui:define>
		<ui:define name="conteudo">
		<!-- 
		DIALOG DA AREA
		-->
			<p:dialog header="Incluir Area" widgetVar="modalCadastroArea" modal="true" onCloseUpdate="formGrupo"  height="390" width="640"  id="boxPesquisarArea">
				<h:form id="formArea">
			    	<h:outputText value="Areas"/>
			   		<h:panelGrid  columns="2" columnClasses="width320 alinhaTopo, width320">
				   		<h:column id="AreasSelecionadas">
							<p:dataTable 	var="areaSelecionada" 
											value="#{controleGrupo.grupo.areas}"
							             	rendered="#{not empty controleGrupo.grupo.areas}"  
											dynamic="true"
											selectionMode="single" 
											update="panelDelArea"
											selection="#{controleGrupo.area}"
											onselectComplete="delArea.show();">
								<p:column>
									<f:facet name="header">  
										<h:outputText value="descri&ccedil;&atilde;o" />
									</f:facet>
									<h:outputText value="#{areaSelecionada.descricao}"/>
								</p:column>
								<p:column styleClass="width80">
									<f:facet name="header">
										<h:outputText value="A&ccedil;&atilde;o" />
									</f:facet>
									<p:commandLink oncomplete="delArea.show();">
										<h:graphicImage url="/images/marcadores/remove.png" alt="Remove Area"/>  
										<f:setPropertyActionListener target="#{controleGrupo.area}" value="#{areaSelecionada}" />
									</p:commandLink>
	                     		</p:column>
							</p:dataTable>
			   			</h:column>
			   			<h:column>
				   			<h:panelGrid  columns="3">
			   					<h:outputText value="Pesquisa:"/>
			   					<h:inputText value="#{controleArea.descricaoPesquisa}"/>
								<h:commandLink action="#{controleArea.pesquisar}" styleClass="iconesLaterais">
									<h:graphicImage url="/images/botoes/btnPesquisar.png" styleClass="hand"/>
									<f:ajax render=":formArea" execute="@form"/>
								</h:commandLink>
			   				</h:panelGrid>
			   				<h:outputText value="Lista de Area"/>
							<p:dataTable value="#{controleArea.lista}" 
							             id="id_ListaArea"
							             var="area" 
							             paginator="true" 
							             rows="5" 
							             dynamic="true" 
							             rendered="#{not empty controleArea.lista}" 
										 firstPageLinkLabel="Primeiro"
							             previousPageLinkLabel="Anterior"
							             nextPageLinkLabel ="Pr&oacute;ximo"
							             lastPageLinkLabel="&Uacute;ltima"
							             emptyMessage="Nenhum resgistro encontrado"
							             errorMessage="Ocorreu um erro"
							             selection="#{controleGrupo.area}" 
							             selectionMode="single">
								<p:column sortBy="#{area.descricao}" styleClass="width60" >
									<f:facet name="header">
										<h:outputText value="Descri&ccedil;&atilde;o" />
									</f:facet>
									<h:outputText value="#{area.descricao}" />
								</p:column>
								<p:column sortBy="#{area.URL}">
									<f:facet name="header">
										<h:outputText value="URL" />
									</f:facet>
									<h:outputText value="#{area.URL}" />
								</p:column>
								<p:column styleClass="width80">
									<f:facet name="header">
										<h:outputText value="A&ccedil;&atilde;o" /> 
									</f:facet>
									<h:commandLink action="#{controleGrupo.addArea}">  
										<h:graphicImage url="/images/marcadores/add.png" alt="adicionar Area"/>  
										<f:setPropertyActionListener target="#{controleGrupo.area}" value="#{area}"/>
										<f:ajax render=":formArea :formGrupo" execute="@form"/>
									</h:commandLink>
	                     		</p:column>
							</p:dataTable>
							
		   				</h:column>
			  		</h:panelGrid>
					<p:dialog header="Confirma&ccedil;&atilde;o" width="300" fixedCenter="true" widgetVar="delArea" visible="false">
						<h:panelGrid columns="2" style="margin-bottom:10px" id="panelDelArea">
							<h:column>
								<h:outputLabel  value="Deseja Excluir?" />
							</h:column>
							<h:column >
								<p:commandButton value="Sim" actionListener="#{controleGrupo.delArea}" update="formGrupo formArea" oncomplete="delArea.hide();"/> 
								<p:commandButton value="Nao" update="form" oncomplete="delArea.hide();"/>
							</h:column>
						</h:panelGrid>
					</p:dialog>
			  	</h:form>
			</p:dialog>
			<h:form id="formGrupo">
				<p:dialog header="Mensagem" id="dialog1" widgetVar="dialog" fixedCenter="true" modal="true" visible="#{facesContext.maximumSeverity != null}">
				   <p:messages/>                     
				</p:dialog>
				<fieldset>
					<p:tabView >
						<p:tab title="Cadastro">						
							<h:panelGrid  columns="2" columnClasses="width50 alinhaDir, width500">
								<h:outputText value=""/>
								<h:outputText value="Os campos com asterisco (*) s&atilde;o de preenchimento obrigat&oacute;rio." styleClass="campoObrigatorio" />								
								<h:outputText value="Grupo:" styleClass=""/>							
								<h:selectOneMenu value="#{controleGrupo.grupo.sistema}" id="listaGrupo">
				                    <f:converter converterId="converteSistema" />
				                    <f:selectItems value="#{controleGrupo.listaSistema}" var="sistema" itemLabel="#{sistema.descricao}" itemValue="#{sistema}"/>
								</h:selectOneMenu>
								<h:outputText value="Descri&ccedil;&atilde;o:" styleClass=""/>
								<h:column>
									<h:inputText  value="#{controleGrupo.grupo.descricao}" requiredMessage="Campo [DESCRICAO] obrigat&oacute;rio" size="80"/>
									<h:outputText value="(*)" styleClass="campoObrigatorio" />
								</h:column>					
							</h:panelGrid>
							<h:panelGrid  columns="2" columnClasses="width150 alinhaDir, width500">
								<h:outputText value="" styleClass="alinhaDir" />
								<h:column>
									<p:tabView id="tabAreas">
										<p:tab title="Areas">
											<h:panelGrid columns="1">
												<p:commandLink oncomplete="modalCadastroArea.show();" >
													<h:graphicImage url="/images/botoes/btnPesquisar.png" styleClass="imageField"/>
												</p:commandLink>
												<p:dataTable 	var="areaGrupo"
																value="#{controleGrupo.grupo.areas}"
												             	rendered="#{not empty controleGrupo.grupo.areas}"  
																dynamic="true"
																selectionMode="single" 
																selection="#{controleGrupo.area}">
													<p:column>  
														<f:facet name="header">  
															<h:outputText value="Descri&ccedil;&atilde;o" />
														</f:facet>  
														<h:outputText value="#{areaGrupo.descricao}"/>
													</p:column>
													<p:column>
														<f:facet name="header">
															<h:outputText value="URL" />
														</f:facet>
														<h:outputText value="#{areaGrupo.URL}" />
													</p:column>
													<p:column styleClass="width80">
														<f:facet name="header">
															<h:outputText value="A&ccedil;&atilde;o" />
														</f:facet>
														<p:commandLink oncomplete="delArea.show();">
															<h:graphicImage url="/images/marcadores/remove.png" alt="Remove Autor"/>  
															<f:setPropertyActionListener target="#{controleGrupo.area}" value="#{areaGrupo}" />
														</p:commandLink>
						                     		</p:column>
												</p:dataTable>
											</h:panelGrid>
										</p:tab>
									</p:tabView>
								</h:column>	
							</h:panelGrid>		
						</p:tab>						
					</p:tabView>
				</fieldset>
				<h:commandLink action="#{controleGrupo.gravar}" styleClass="alinhaDir">
					<h:graphicImage url="/images/botoes/btnGravar.png" class="btnAcoes"/>
				</h:commandLink>
				<h:commandLink action="#{controleArea.limpar}">
					<h:graphicImage url="/images/botoes/btnLimpar.png" class="btnAcoes"/>
					<f:ajax render=":formGrupo :formArea"/>
				</h:commandLink>
				<h:outputLink value="manutencao.jsf">
					<h:graphicImage url="/images/botoes/btnPesquisar.png" class="btnAcoes"/>
				</h:outputLink>
			</h:form>
		</ui:define>
	</ui:composition>
</html>